package main

import (
	"fmt"
	"strconv"
)

func upperTriangle(n int) {
	s := []string{} // use slice to store all numbers

	for i := n; i >= 1; i-- { // n is the max number we want to print

		s = append(s, strconv.Itoa(i)) // convert each number to string in reverse order
		// it's easier to compute the number of spaces per each number
		// while it was not printed out
	}
	var r_line int = n // r_line is the remain line to print
	for i := 0; i < n; i++ {
		var l_s int = 0 // length of space per line
		for i, v := range s {
			if i < r_line-1 {
				l_s += len(v) // sum up each not printed space per length for each number
			}
		}
		l_s = l_s + r_line - 1 // add space for between each number
		for i := 0; i < l_s; i++ {
			fmt.Printf(" ") // print each space
		}
		for i := r_line - 1; i < n-1; i++ {
			fmt.Printf("%s ", s[i]) // print each number
		}
		fmt.Printf("%s", s[n-1]) // print the last number prevent print the space after the last number

		fmt.Println() // print the newline
		r_line--      // decrease remain print line
	}
}

func main() {
	upperTriangle(15)
}
